package uriel.frankel;

import java.text.DecimalFormat;

import uriel.frankel.model.Algorithem;




import android.app.Activity;
import android.content.Intent;
import android.view.View.OnClickListener;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class Result extends Activity implements OnClickListener  {

	TextView NetoInBank;
	TextView socialText;
	TextView TaxText;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.result);
		NetoInBank = (TextView) findViewById(R.id.textView2);
		socialText = (TextView) findViewById(R.id.textView4);
		TaxText = (TextView) findViewById(R.id.textView6);
	


		Algorithem irs = Algorithem.GetInstance();
		Double res = irs.GetInTheBank();
		res = Math.rint(res);
		DecimalFormat formatter = new DecimalFormat("#,###");
		NetoInBank.setText(formatter.format(res));
		if(Algorithem.GetInstance().isLeasing()){
			NetoInBank.setClickable(true);
			NetoInBank.setOnClickListener(this);
		}
		
		Double social = irs.GetSocialAlocation();
		social = Math.rint(social);
		socialText.setText(formatter.format(social));
		socialText.setOnClickListener(this);

		Double taxes = irs.GetHealthTax() + irs.GetIncomeTax() + irs.getsocialSecurity();
		taxes = Math.rint(taxes);
		TaxText.setText(formatter.format(taxes));
		TaxText.setOnClickListener(this);

		if(PreferenceManager.getDefaultSharedPreferences(this).getBoolean("leasing", false)){
			runOnUiThread(new Runnable() {
				public void run() {
					Toast.makeText(getApplicationContext(),
							"החישוב כולל ליסינג", Toast.LENGTH_SHORT).show();	
				}
			});
		}
	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.textView4:

         	  Intent SocialIntent = new Intent(Result.this, SocialDialog.class);
         	 Result.this.startActivity(SocialIntent);
    	     
			break;
		case R.id.textView6:

         	  Intent TaxesIntent = new Intent(Result.this, TaxesDialog.class);
         	 Result.this.startActivity(TaxesIntent);
    	     
			break;
			case R.id.textView2:
				Toast.makeText(this, "ליסינג : " +Algorithem.GetInstance().getMonthlyPaymentForCar(), Toast.LENGTH_SHORT).show();
				break;
		default:
			break;
		}
		
	}

	


}
